# !/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
===========================
@Time : 2022/7/10 0010 15:03
@Author : 测试开发工程师
@File : base_api.py
@Software: PyCharm
============================
"""

import requests
from apitest.Test_frame.utils.log_utils import logger


class BaseApi:
    BASE_URL = ""

    def send_api(self, req):
        """
        对 requests 的二次封装，返回对应接口响应数据
        """
        # 拼接 url -> base_url + path
        if self.BASE_URL:
            req["url"] = self.BASE_URL + req.get("url")
        logger.info(f"发起接口请求时的请求数据为：{req}")
        r = requests.request(**req)
        logger.info(f"发起请求后收到的响应数据为：{r.text}")
        return r
